package com.jshop.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author jon
 * @date 2019/11/25 14:07
 */
public class PropertiesUtils {
    @Autowired
    private Environment env;
    public static String getValueByKey(String filePath, String key) {
        Properties pps = new Properties();
        InputStream in = null;
        try {
            // in = new BufferedInputStream(new FileInputStream(filePath));
            in = PropertiesUtils.class.getResourceAsStream(filePath);
            pps.load(in);
            String value = pps.getProperty(key);
            System.out.println(key + " = " + value);
            return value;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) {
        String application = getValueByKey("application", "wx.cart.notifyUrl");
        System.out.println(application);
    }
}
